// pages/my/my.js
const CONFIG = require('../../../config');
const request = require('../../../utils/request.js');  
const util = require('../../../utils/util.js');  
const { addZero,$await } = require('../../../utils/util');  // 格式化时间
import {commonAPI} from '../../../api/common/index'
Component({
  properties:{
    list:{
        type:Object,
        value:'',
    },
    isTitle:{
      type:Boolean,
      value:'',
    }
  },
  observers : {
    'list': function (goodsPrices) {
      console.log("Component下的observers监听触发", goodsPrices)
      this.setData({
        channelList:goodsPrices
      })
      for(let i=0;i<this.data.channelList.videos.length;i++){
        this.setData({
          ['channelList.videos['+i+'].show_spectators']:util.toFix(Number(this.data.channelList.videos[i].show_spectators),10000,'w')
        })
        this.setData({
          ['channelList.videos['+i+'].duration']:util.formatSeconds(Number(this.data.channelList.videos[i].duration))
        })
      }
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    imgUrl : CONFIG.imgUrlImg ,
    radioInfo:{
    }
  },
  lifetimes:{
    created() {
    },
  },

  pageLifetimes:{
    show: function () {
      console.log(this.data)
     },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    async collection(e){
      const { type } = e.currentTarget.dataset;
      let params = {
        'channel_number':this.data.channelList.channel_number,
        'type':type
      }
      const [err,res] = await $await(commonAPI.followChannel({...params}))
      if(res){
        if(type == '1'){
          this.setData({
            ['channelList.is_follow']:true
          })
        }else{
          this.setData({
            ['channelList.is_follow']:false
          })
        }
      }
    },
    todetail: function(e){
      console.log(e)
      const { id,playid } = e.currentTarget.dataset;
      if(this.data.isTitle){
        wx.navigateTo({
          url: '/pages/playback/index?play_id=' + playid,
        })
      }else{
        wx.navigateTo({
          url: `/pages/shortVideo/index?number=${id}`
        })
      }
    },
    bindtapItem(e){
      console.log(e)
      wx.navigateTo({
        url: '/pages/playback/index?play_id=' + e.currentTarget.dataset.play_id,
      })
    },
  }
})